/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.wisc.csvParser.plugins;
import com.wisc.csvParser.IDateTimeParser;

/**
 *
 * @author glocke-ou
 */
public class DateTimePicker extends javax.swing.JDialog  {
    /** A return status code - returned if Cancel button has been pressed */
    public static final int RET_CANCEL = 0;
    /** A return status code - returned if OK button has been pressed */
    public static final int RET_OK = 1;
    private int returnStatus = RET_CANCEL;

    private IDateTimeParser dtParser;
    private DataParserTableBased.TableBasedFile dpTable;

    /** Creates new customizer DateTimePicker */
    public DateTimePicker(java.awt.Frame parent, boolean modal,
            DataParserTableBased.TableBasedFile dpParent) {
        super(parent, modal);
        initComponents();
        dpTable = dpParent;
    }

    public int getReturnStatus() {
        return returnStatus;
    }

    public DataParserTableBased.TableBasedFile getReturnType(){
        return dpTable;
    }

    private void doClose() {
        if (returnStatus == RET_OK) {
            dpTable.setDateTimeParser(dtParser);
        }
        setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the FormEditor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        buttonGroup4 = new javax.swing.ButtonGroup();
        buttonGroup5 = new javax.swing.ButtonGroup();
        buttonGroup6 = new javax.swing.ButtonGroup();
        buttonGroup7 = new javax.swing.ButtonGroup();
        oneColumnButton = new javax.swing.JRadioButton();
        MulColumnsButton = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        SaveButton = new javax.swing.JButton();
        CancelButton = new javax.swing.JButton();

        buttonGroup1.add(oneColumnButton);
        oneColumnButton.setText("One column; yyyy-MM-dd HH:mm:ss (time optional)");
        oneColumnButton.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                oneColumnButtonStateChanged(evt);
            }
        });
        oneColumnButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                oneColumnButtonActionPerformed(evt);
            }
        });

        buttonGroup1.add(MulColumnsButton);
        MulColumnsButton.setSelected(true);
        MulColumnsButton.setText("Multiple Columns; year, month, day, optional time");
        MulColumnsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MulColumnsButtonActionPerformed(evt);
            }
        });

        jLabel1.setText("Please select the date/time format of the data:");

        SaveButton.setText("Save");
        SaveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveButtonActionPerformed(evt);
            }
        });

        CancelButton.setText("Cancel");
        CancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(41, 41, 41)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(MulColumnsButton)
                            .add(oneColumnButton)
                            .add(jLabel1))
                        .addContainerGap(34, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(SaveButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(CancelButton)
                        .add(125, 125, 125))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(oneColumnButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(MulColumnsButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(SaveButton)
                    .add(CancelButton))
                .addContainerGap(21, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void oneColumnButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oneColumnButtonActionPerformed
        dtParser = new DateTimeParserTableBased();
    }//GEN-LAST:event_oneColumnButtonActionPerformed

    private void MulColumnsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MulColumnsButtonActionPerformed
        dtParser = new DateTimeParserTableBasedChoice();
    }//GEN-LAST:event_MulColumnsButtonActionPerformed

    private void SaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveButtonActionPerformed
        returnStatus = RET_OK;
        doClose();
    }//GEN-LAST:event_SaveButtonActionPerformed

    private void CancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelButtonActionPerformed
        returnStatus = RET_CANCEL;
        doClose();
    }//GEN-LAST:event_CancelButtonActionPerformed

    private void oneColumnButtonStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_oneColumnButtonStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_oneColumnButtonStateChanged


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CancelButton;
    private javax.swing.JRadioButton MulColumnsButton;
    private javax.swing.JButton SaveButton;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.ButtonGroup buttonGroup4;
    private javax.swing.ButtonGroup buttonGroup5;
    private javax.swing.ButtonGroup buttonGroup6;
    private javax.swing.ButtonGroup buttonGroup7;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JRadioButton oneColumnButton;
    // End of variables declaration//GEN-END:variables

}
